type IState = {
    sum: number,
    school: string,
    subject: string,
}
export default {
    namespaced: true, //添加命名空间就可以定位mapState等参数，函数的位置
    actions: {
        increment(context: any, value: number) {
            context.commit("increment", value);
        },
        decrement(context: any, value: number) {
            context.commit("decrement", value);
        },
        incrementOdd(context: any, value: number) {
            if (context.state.sum % 2 !== 0) {
                context.commit("increment", value);
            }
        },
        incrementWait(context: any, value: number) {
            setTimeout(() => {
                context.commit("increment", value);
            }, 500);
        },
    },
    mutations: {
        increment(state: IState, value: number) {
            state.sum += value;
        },
        decrement(state: IState, value: number) {
            state.sum -= value;
        },
    },
    state: {
        sum: 0,
        school: "尚硅谷",
        subject: "前端",
    },
    getters: {
        bigSum(state: IState) {
            return state.sum * 10;
        },
    },
};
